﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Linq;
using System.Data.OracleClient;

public partial class quanlytaikhoan : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataConnection.str = @"Data Source=xe;User ID=ODER;Password=12345";
        if (!IsPostBack)
        {
            MultiView1.ActiveViewIndex = 0;
            // get TenDN from Session
            string tendn = Convert.ToString(Session["TenDN"]);

            // display UserName
            lbusername.Text = tendn;            
            
            //put @param tendn into Sp(p_tendn)  
            OracleParameter[] thamso = new OracleParameter[]
            {
                new OracleParameter("p_tendn",tendn),   
            };

            // Get datatable Users by TenDN
            DataTable dt = DataConnection.GetDatatableByStoreProcedureNameCursor("NGOCTRAN.sp_getUserByTenDN", thamso);
            
            // Display data into Screen
            txtdiachi.Text = dt.Rows[0]["Diachi"].ToString();
            txthoten.Text = dt.Rows[0]["TenUsers"].ToString();
            txtsdt.Text = dt.Rows[0]["SDT"].ToString();          
        }
    }
    protected void bthuy_Click(object sender, EventArgs e)
    {
        //if user click Huy button, redirect to TrangChu Page.
        Response.Redirect("trangchu.aspx");
    }
    protected void btdoimatkhau_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 1;
        lbloidoimatkhau.Visible = false;
    }
    protected void btndoimatkhau_Click(object sender, EventArgs e)
    {
        mahoa mk = new mahoa();


        string matkhaumoi = mk.mahoamk(txtmatkhaumoi.Text, true);
        string matkhaucu = mk.mahoamk(txtmatkhaucu.Text, true);
        string tendn = Convert.ToString(Session["TenDN"]);
        OracleParameter[] thamso = new OracleParameter[]
        {
            new OracleParameter("p_tendn", tendn),
            new OracleParameter("p_matkhaudn",matkhaucu),
        };

        // Get User using TenDN and Password
        DataTable dt = DataConnection.GetDatatableByStoreProcedureNameCursor("NGOCTRAN.sp_getUserByTenDNMatKhauDN", thamso);
        // if correct both TenDN and MatKhauDN.
        if (dt.Rows.Count > 0)
        {
           
            OracleParameter[] thamso1 = new OracleParameter[]
            {
                new OracleParameter("p_matkhaudn",matkhaumoi),
                new OracleParameter("p_tendn",tendn),
            };

            // Update new password.
            DataConnection.GetDatatableByStoreProcedureName("NGOCTRAN.UPDATE_PASS",thamso1);

            // redirect to Thongbao page and display congratulation message.
            Response.Redirect("thongbao.aspx?ID=4");
        }
        else
        {
            lbloidoimatkhau.Visible = true;
            lbloidoimatkhau.Text = "Mật khẩu cũ của bạn không đúng, xin hay nhập lại";

        }
    }
    protected void btnhuy_Click(object sender, EventArgs e)
    {
         Response.Redirect("trangchu.aspx");
    }
    protected void btnlaymatkhau_Click(object sender, EventArgs e)
    {
        string tendn = lbusername.Text;
        string hoten = txthoten.Text;
        string diachi = txtdiachi.Text;
        int sodt = int.Parse(txtsdt.Text);
     
       
        OracleParameter[] thamso = new OracleParameter[]
        {
            new OracleParameter("P_TENDN",tendn),
            new OracleParameter("P_TENUSERS",hoten),
            new OracleParameter("P_DIACHI",diachi),
            new OracleParameter("P_SDT",sodt),
        };
        DataConnection.GetDatatableByStoreProcedureName("NGOCTRAN.UPDATE_inforUserByTenDN", thamso);
        Response.Redirect("thongbao.aspx?ID=3");

    }
    protected void MultiView1_ActiveViewChanged(object sender, EventArgs e)
    {

    }
}